package com.yang.chatimage.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.image.ImageOptionsBuilder;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.openai.OpenAiImageClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ImageController {
    @Resource
    private OpenAiImageClient openAiImageClient;

    @GetMapping("/ai/draw")
    public String drawImage(@RequestParam(value = "msg") String msg){
        ImageResponse response = openAiImageClient.call(new ImagePrompt(msg,
                ImageOptionsBuilder
                        .builder()
                        .withModel("dall-e-3") //绘画模型
                        .withN(1) //生成图像的个数
                        .withWidth(1024) //图像宽度 默认值
                        .withHeight(1024) //图像高度 默认值
                        .build()
                )
        );
        return response.getResult().getOutput().getUrl();
    }
}
